#ifndef SPRITEANIMATOR_H_INCLUDED
#define SPRITEANIMATOR_H_INCLUDED

#include <vector>
#include <string>

namespace Oribi
{
    struct SpriteAnimFrame
    {
        SDL_Rect rect;
        Uint32 ticks;
    };

    class ConfigFile;

    struct SpriteAnimation
    {
        SpriteAnimation(){frames.clear();}
        SpriteAnimation(std::string name, ConfigFile& f);

        bool loadFromFile(std::string name, ConfigFile& f);

        std::vector<SpriteAnimFrame> frames;
    };

    #define SPR_ANIM_DO_NOTHING 0
    #define SPR_ANIM_REMOVE     1
    #define SPR_ANIM_DESTROY    2

    class Sprite;

    class SpriteAnimator
    {
    public:
        virtual ~SpriteAnimator(){}
        virtual SpriteAnimator *clone() const = 0;
        virtual int animateSprite(Sprite&) = 0;
    protected:
    };

    enum SprAnimState
    {
        SprAnimRunning,
        SprAnimPaused
    };

    class SprAnimRun : public SpriteAnimator
    {
    public:
        SprAnimRun(const SpriteAnimation& an, int loops = -1, bool destroy = false);
        SprAnimRun(const SprAnimRun&);

        SpriteAnimator *clone() const;
        int animateSprite(Sprite&);

        void setDestroy(bool);
        bool getDestroy();

        void resetTime();

        void pause();
        void run();
        void stop();
        void restart();
        void restart(int nLoops);

        int switchFrame(Sprite& spr);

        SpriteAnimation anim;
    private:
        int state;
        bool destroy;
        int frame, nFrames,
            nLoopsRemaining;
        Uint32 startTime;
        Uint32 switchTime;
    };
}

#endif // SPRITEANIMATOR_H_INCLUDED
